package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.VmType;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.VmTypeDTO;
import com.heima.service.VmTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service/vmType")
public class VmTypeController {

    @Autowired
    private VmTypeService vmTypeService;

    @GetMapping("/search")
    public PageResult vmTypeQuery(PageQueryDTO dto){
        log.info("售货机类型列表(搜索)：{}",dto);
        return vmTypeService.vmTypeQuery(dto);
    }

    @PostMapping
    public Boolean add(@RequestBody VmType vmType){
        log.info(" 新增设备类型：{}",vmType);
        return vmTypeService.add(vmType);
    }

    @PutMapping("/{typeId}")
    public Boolean update(@PathVariable Integer typeId,@RequestBody VmType vmType){
        log.info("修改设备类型：{}，{}",typeId,vmType);
        return vmTypeService.update(typeId,vmType);
    }

    @DeleteMapping("/{typeId}")
    public Boolean delete(@PathVariable Integer typeId){
        log.info("删除设备类型：{}",typeId);
        return vmTypeService.delete(typeId);
    }

    @GetMapping("/{typeId}")
    public VmType queryTypeId(@PathVariable Integer typeId){
        log.info("售货机类型详情：{}",typeId);
        return vmTypeService.queryTypeId(typeId);
    }

}
